//
//  PPTToImageToolinWKWeb.m
//  PPTToImage
//
//  Created by tql on 2020/8/19.
//  Copyright © 2020 alex. All rights reserved.
//

#import "PPTToImageToolinWKWeb.h"

@interface PPTToImageToolinWKWeb ()<WKUIDelegate,WKNavigationDelegate>
{
   __block CGFloat pptWidth;
    __block CGFloat pptHeight ;
}
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) NSMutableArray *pageInfoArr;          // 存储 ppt 每一页尺寸信息
@property (nonatomic, assign) NSInteger pageCount;                  // ppt页数
@property (nonatomic, strong) NSMutableArray *pptImageArr;          // 存储PPT生成的图片
@property (nonatomic, copy) void (^callback)(NSArray * images);     // 图片回调
@property (nonatomic, copy) void (^progress)(CGFloat value);        // 转换进度条

@end

@implementation PPTToImageToolinWKWeb

- (void)pptToImageWithPPTFileUrl: (NSString *) pptFileUrl
                        progress: (void (^)(CGFloat value)) progress
                      completion: (void (^)(NSArray * images)) completion{
    [self.pageInfoArr removeAllObjects];
    [self.pptImageArr removeAllObjects];
    self.webView = nil;
    self.callback = completion;
    self.progress = progress;
    [self p_initWebView];
    [self p_loadPPT:pptFileUrl];
}

#pragma -mark UIWebViewDelegate
//- (void)webViewDidFinishLoad:(UIWebView *)webView {
//    //     [self p_printHtml];  // 用于获取页面html 代码
//    [self p_getTTPInfo];
//}
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    NSLog(@"%s",__func__);
    [self p_printHtml];
    [self p_getTTPInfo];
}

// 初始化,并注册JS调用方法
- (void)p_initWebView{
    
    WKWebViewConfiguration *configer = [[WKWebViewConfiguration alloc]init];
    WKPreferences *ces = [[WKPreferences alloc]init];
//    ces.javaEnabled = YES;
    ces.javaScriptEnabled = YES;
    ces.javaScriptCanOpenWindowsAutomatically= YES;
    configer.preferences = ces;
    WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:configer];
    webView.backgroundColor = [UIColor whiteColor];
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
    
    self.webView = webView;
    
    if (self.parentView) {
        self.webView.frame =CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height);// self.parentView.frame;
        [self.parentView addSubview:self.webView];
    }
}

// 加载PPT
- (void)p_loadPPT:(NSString *) pptFileUrl {
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:pptFileUrl]];
    [self.webView loadRequest:request];
}

// 查看 html结构
- (void)p_printHtml{
    NSLog(@"%s",__func__);
//    NSString *html = [self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerHTML"];
//    NSLog(@"%@",html);
    
//    dispatch_async(dispatch_get_main_queue(), ^{
        
//        dispatch_group_t group = dispatch_group_create();
//        dispatch_queue_t   queue = dispatch_queue_create("com.queue", DISPATCH_QUEUE_SERIAL);
//
//        dispatch_group_enter(group);
//        dispatch_group_async(group, queue, ^{
            //            dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
            
    [self.webView evaluateJavaScript:@"document.documentElement.innerHTML" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
        NSLog(@"%@",content);
        if (error) {
            NSLog(@"1111%@",error.localizedDescription);
        }
        //                    dispatch_semaphore_signal(semaphore);  //获取block结果后唤醒
        //                dispatch_group_leave(group);
        
    }];
    //        });
//            dispatch_semaphore_wait(semaphore,  DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
//    });
}

// 获取 ppt 信息,PPT页数,以及尺寸信息
- (void)p_getTTPInfo{
    NSLog(@"%s",__func__);
    // 获取PPT页数
//    NSInteger pageCount = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('slide').length"] integerValue];
//
    
//    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    [self.webView evaluateJavaScript:@"document.getElementsByClassName('slide').length" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
        NSLog(@"silder = %@",content);
        if (error) {
                  NSLog(@"2222%@",error.localizedDescription);
              }
        self.pageCount = [content integerValue];
//        dispatch_semaphore_signal(semaphore);  //获取block结果后唤醒
        dispatch_async(dispatch_get_main_queue(), ^{
            [self clear];
        });
        
    }];
    
//    dispatch_semaphore_wait(semaphore,  DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
    
}

-(void)clear{
    
    
    
    // 清除一些间距信息
//    [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.margin = '0';"];
//    [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.style.padding = '0';"];
    
    NSLog(@"3>>>>>");
//    dispatch_semaphore_t semaphore1 = dispatch_semaphore_create(0);

    [self.webView evaluateJavaScript:@"document.body.style.margin = '0';" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
        NSLog(@"mmmmmmmm%@",content);
        if (error) {
                  NSLog(@"333%@",error.localizedDescription);
              }
//        dispatch_semaphore_signal(semaphore1);  //获取block结果后唤醒

        dispatch_async(dispatch_get_main_queue(), ^{
                 [self clearPadding];
             });
        
    }];
//    dispatch_semaphore_wait(semaphore1,   DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
    
NSLog(@"3>>>>><<<<,,");
    

}

-(void)clearPadding{
        NSLog(@"%s",__func__);

//    dispatch_semaphore_t semaphore12 = dispatch_semaphore_create(0);

    [self.webView evaluateJavaScript:@"document.body.style.padding = '0';" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
        NSLog(@"cccccccccccc%@",content);
        if (error) {
            NSLog(@"444%@",error.localizedDescription);
        }
        //        dispatch_semaphore_signal(semaphore12);  //获取block结果后唤醒
        dispatch_async(dispatch_get_main_queue(), ^{
            [self calculateWidth];
        });
    }];
//    dispatch_semaphore_wait(semaphore12,  DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
    
    
}
-(void)calculateWidth{
    NSLog(@"%s",__func__);

    [self.webView evaluateJavaScript:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).width)" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
           NSLog(@"wwwww%@",content);
        pptWidth = [content floatValue];
        
           if (error) {
               NSLog(@"444%@",error.localizedDescription);
           }
           //        dispatch_semaphore_signal(semaphore12);  //获取block结果后唤醒
           dispatch_async(dispatch_get_main_queue(), ^{
               [self calculateHeight];
           });
       }];
    
}
-(void)calculateHeight{
    NSLog(@"%s",__func__);

    [self.webView evaluateJavaScript:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).height)" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
              NSLog(@"hhhh:%@",content);
           pptHeight = [content floatValue];
           
              if (error) {
                  NSLog(@"444%@",error.localizedDescription);
              }
              //        dispatch_semaphore_signal(semaphore12);  //获取block结果后唤醒
              dispatch_async(dispatch_get_main_queue(), ^{
                  [self calculatarray];
              });
          }];
    
}

-(void)clearPaddingetwidth{
    
    
    // 获取没一页信息
    for (NSInteger i = 0; i< self.pageCount; i++ ){
//        NSInteger pageWidth = [[self.webView stringByEvaluatingJavaScriptFromString:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).width)"] integerValue];
//        NSInteger pageHeight = [[self.webView stringByEvaluatingJavaScriptFromString:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).height)"] integerValue];
        
        
       __block NSInteger pageWidth  = 0;
       __block NSInteger pageHeight = 0;
        dispatch_semaphore_t semaphore123 = dispatch_semaphore_create(0);

          [self.webView evaluateJavaScript:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).width)" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
              NSLog(@"%@",content);
              if (error) {
                        NSLog(@"555%@",error.localizedDescription);
                    }
              pageWidth = [content integerValue];
              dispatch_semaphore_signal(semaphore123);  //获取block结果后唤醒

          }];
          dispatch_semaphore_wait(semaphore123,   DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
        
        dispatch_semaphore_t semaphore1234 = dispatch_semaphore_create(0);

          [self.webView evaluateJavaScript:@"parseInt(window.getComputedStyle(document.getElementsByClassName('slide')[0]).height)" completionHandler:^(id _Nullable content, NSError * _Nullable error) {
              NSLog(@"%@",content);
              if (error) {
                        NSLog(@"7777%@",error.localizedDescription);
                    }
              pageHeight = [content integerValue];
              dispatch_semaphore_signal(semaphore1234);  //获取block结果后唤醒

          }];
          dispatch_semaphore_wait(semaphore1234, DISPATCH_TIME_FOREVER);    //加锁，不让方法结束
        
        
        
        
        
        CGSize size = CGSizeMake(pageWidth, pageHeight);
        [self.pageInfoArr addObject:@(size)];
    }
    
    
    
    
    
    
    
    
    
    
    [self p_cropImage];
    
}
-(void)calculatarray{
    
    NSLog(@"%s",__func__);
    
    [self calculatarray2];
    return;
    
    
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    CGFloat pptHeightNEW = screenHeight/10.0*5;
    CGFloat ppTWidthNEW = pptWidth/pptHeight*pptHeightNEW;
    
    ppTWidthNEW = pptWidth;
    pptHeightNEW = pptHeight;
    
    NSLog(@"pptHeightNEW,ppTWidthNEW:(%f,%f)",pptHeightNEW,ppTWidthNEW);
    
    if (self.pageCount<10) {
//        self.webView.frame = CGRectMake(0, 0, pptWidth/pptWidth*screenWidth, pptHeight*self.pageCount/pptWidth*screenWidth);
        
        self.webView.frame = CGRectMake(0, 0, ppTWidthNEW,
                                        pptHeightNEW*self.pageCount );

    }else{
//        self.webView.frame = CGRectMake(0, 0, pptWidth/pptWidth*screenWidth, pptHeight*10/pptWidth*screenWidth);
        
        self.webView.frame = CGRectMake(0, 0, ppTWidthNEW, pptHeightNEW*10);

    }
    
     
        
    for (NSInteger i = 0; i< self.pageCount; i++ ){

//        CGSize size = CGSizeMake(pptWidth/pptWidth*screenWidth, pptHeight/pptWidth*screenWidth);
        
        CGSize size = CGSizeMake(ppTWidthNEW, pptHeightNEW);

        [self.pageInfoArr addObject:@(size)];
    }
    [self p_cropImage];

}
-(void)calculatarray2{
    
    NSLog(@"%s",__func__);
    NSLog(@".scrollView.contentSize.height:%f",self.webView.scrollView.contentSize.height);
    NSLog(@"pageCount:%ld",self.pageCount);
    NSLog(@"pptHeight,pptWidth:%f %f",pptHeight,pptWidth);
    
    
    CGFloat PPTscreenWidth = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat pptScreenHeight =  pptHeight/pptWidth*PPTscreenWidth;
    
    pptScreenHeight = self.webView.scrollView.contentSize.height/self.pageCount;
    
    NSLog(@"PPTscreenWidth,pptScreenHeight:%f %f",PPTscreenWidth,pptScreenHeight);
    
    
    self.webView.frame = CGRectMake(0, 0, PPTscreenWidth , pptScreenHeight );

    for (NSInteger i = 0; i< self.pageCount; i++ ){
        
        //        CGSize size = CGSizeMake(pptWidth/pptWidth*screenWidth, pptHeight/pptWidth*screenWidth);
        
        CGSize size = CGSizeMake(PPTscreenWidth, pptScreenHeight);
        
        [self.pageInfoArr addObject:@(size)];
    }
//    [self p_cropImage2];
    [self p_cropimage333];
    
}


- (UIImage*)captureView:(WKWebView *)webView
{
    UIImage* image = nil;
        //优化图片截取不清晰
    UIGraphicsBeginImageContextWithOptions(webView.scrollView.contentSize, true, [UIScreen mainScreen].scale);
    {
        CGPoint savedContentOffset = webView.scrollView.contentOffset;
        CGRect savedFrame = webView.scrollView.frame;
        webView.scrollView.contentOffset = CGPointZero;
        webView.scrollView.frame = CGRectMake(0, 0, webView.scrollView.contentSize.width, webView.scrollView.contentSize.height);
        for (UIView * subView in webView.subviews) {
            [subView drawViewHierarchyInRect:subView.bounds afterScreenUpdates:YES];
        }
        image = UIGraphicsGetImageFromCurrentImageContext();
        webView.scrollView.contentOffset = savedContentOffset;
        webView.scrollView.frame = savedFrame;
    }
    UIGraphicsEndImageContext();
    if (image != nil) {
        return image;
    }
    return nil;
}


- (UIImage*)captureView:(WKWebView *)webView fromStartHeight:(CGFloat)starth andEndHeight:(CGFloat)endH
{
    UIImage* image = nil;
        //优化图片截取不清晰
    UIGraphicsBeginImageContextWithOptions(webView.scrollView.frame.size, true,1?1: [UIScreen mainScreen].scale);
    {
        CGPoint savedContentOffset = webView.scrollView.contentOffset;
//        CGRect savedFrame = webView.scrollView.frame;
        webView.scrollView.contentOffset = CGPointMake(0, starth);
//        webView.scrollView.frame = CGRectMake(0, 0, webView.scrollView.contentSize.width, webView.scrollView.contentSize.height);
        for (UIView * subView in webView.subviews) {
            [subView drawViewHierarchyInRect:subView.bounds afterScreenUpdates:YES];
        }
        image = UIGraphicsGetImageFromCurrentImageContext();
//        webView.scrollView.contentOffset = CGPointMake(0, endH);
//        webView.scrollView.frame = savedFrame;
    }
    UIGraphicsEndImageContext();
    if (image != nil) {
        return image;
    }
    return nil;
}
- (UIImage *)sb_creatImageByView:(UIView *)view {
    CGRect rect = view.frame;
    
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}

- (UIImage *)createImageWithView:(UIView *)view {
    
    CGContextRef currentCTX  = UIGraphicsGetCurrentContext();
//    CGContextSaveGState(currentCTX);
    CGSize s = view.bounds.size;
    //第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果，需要传NO，否则传YES。第三个参数就是屏幕密度了，设置为[UIScreen mainScreen].scale可以保证转成的图片不失真。
    UIGraphicsBeginImageContextWithOptions(s, YES,[UIScreen mainScreen].scale);
    [view.layer renderInContext:currentCTX];
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
//    CGContextRestoreGState(currentCTX);
    UIGraphicsEndImageContext();
    return image;
}

-(void)p_cropimage333{
    
    [self recursive_p_cropimage:0];
    
    return;
    NSLog(@"%s",__func__);
   __block CGFloat offset = 0;
    CGSize size = [self.pageInfoArr[0] CGSizeValue];
    __block BOOL  canOffSet= YES;
    do {
        __weak typeof(self) weakself= self;
        
        if (!canOffSet) {
            NSLog(@"rrrrrr");
//            return;
        }else{
            if (canOffSet) {
                canOffSet = NO;
            }
            self.webView.scrollView.contentOffset = CGPointMake(0, offset);
            WKSnapshotConfiguration *configure= [WKSnapshotConfiguration new];
            configure.rect = CGRectMake(0, offset, size.width, size.height);
            configure.snapshotWidth =  @(size.width);
            //        configure.afterScreenUpdates = YES;
            [self.webView takeSnapshotWithConfiguration:configure completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) {
                
                NSLog(@"takeSnapshotWithConfiguration::%@",snapshotImage);
                [weakself.pptImageArr addObject:snapshotImage];
                offset+=size.height;
                canOffSet = YES;
            }];
        }
    NSLog(@"fasdfadfsdfdfasdfasdfsdaf----a");
    } while ( 0&&offset<size.height*self.pageInfoArr.count);
    return;
    NSLog(@"fasdfadfsda");
    if (self.callback) {
//        [self.webView removeFromSuperview];
//        self.webView = nil;
        
        self.callback(self.pptImageArr);
    }
    
}
-(void)recursive_p_cropimage:( CGFloat)outoffset{
    
    __block CGFloat offset = outoffset;
      CGSize size = [self.pageInfoArr[0] CGSizeValue];
//      __block BOOL  canOffSet= YES;
    __weak typeof(self) weakself= self;
//    self.webView.scrollView.contentOffset = CGPointMake(0, offset);
    [self.webView.scrollView setContentOffset:CGPointMake(0, offset) animated:NO];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSLog(@"offset===%f",offset);
        WKSnapshotConfiguration *configure= [WKSnapshotConfiguration new];
//        configure.rect = CGRectMake(0, offset, size.width, size.height);
//        configure.snapshotWidth =  @(size.width);
//                configure.afterScreenUpdates = YES;
        [self.webView takeSnapshotWithConfiguration:configure completionHandler:^(UIImage * _Nullable snapshotImage, NSError * _Nullable error) {
            
            NSLog(@"takeSnapshotWithConfiguration::%@ %@",snapshotImage,error.localizedDescription);
            [weakself.pptImageArr addObject:snapshotImage];
            offset+=size.height;
            if (offset<=size.height*(self.pageInfoArr.count-1)+10) {
                
                [weakself recursive_p_cropimage:offset];
            }else{
//                return;
                if (weakself.callback) {
                    [weakself.webView removeFromSuperview];
                    weakself.webView = nil;
                    weakself.callback(weakself.pptImageArr);
                }
            }
        }];
    });
}

//-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//    NSLog(@"%@")
//}

-(void)p_cropImage2{

  
    
    
    
    CGFloat offsetheight = 0;

    for (int i = 0; i< self.pageInfoArr.count ; i++) {
        CGSize size = [self.pageInfoArr[0] CGSizeValue];

        self.webView.scrollView.contentOffset = CGPointMake(0, offsetheight*i+0);
        CGFloat start= offsetheight;
        CGFloat endHeig = offsetheight +size.height;
        
//        UIImage *pptImage = [self captureView:self.webView fromStartHeight:start andEndHeight:endHeig];
        
//        UIImage *pptImage = [self sb_creatImageByView:self.webView];
        UIImage *pptImage= [self createImageWithView:self.webView];
        
        
        offsetheight += (size.height*1 + 0);
        [self.pptImageArr addObject:pptImage];
        if (self.progress) {
            self.progress((CGFloat)self.pptImageArr.count / (CGFloat)self.pageInfoArr.count);
        }

    }
    
    if (self.callback) {
        [self.webView removeFromSuperview];
        self.webView = nil;
        
        self.callback(self.pptImageArr);
    }
    
}

// 通过绘制进行截图
- (void)p_cropImage{
    
    
    
    CGFloat offsetheight = 0;
    
    for (int i = 0; i< self.pageInfoArr.count/10+1; i++) {
        self.webView.scrollView.contentOffset = CGPointMake(0, offsetheight*i+0);
        UIImage *wholeImage= [self captureView:self.webView];
        UIImage *wimage2 = [self sb_creatImageByView:self.webView];
        
        
        UIImage *image= [self imageWithView:self.webView frame:CGRectMake(0, 0, self.webView.frame.size.width, self.webView.frame.size.height)];
        
        
        CGSize size = [self.pageInfoArr[0] CGSizeValue];
        offsetheight += (size.height*10 + 0);
        for (int j = 0; j<10; j++) {
            
            //        self.webView.frame = CGRectMake(0, 0, size.width, size.height);
            
            if (j+10*i>=self.pageInfoArr.count) {
                break;
            }
            UIImage * pptImage =    [self imageWithView:self.webView frame:CGRectMake(0, (j*size.height), size.width, size.height)];
            [self.pptImageArr addObject:pptImage];
            if (self.progress) {
                self.progress((CGFloat)self.pptImageArr.count / (CGFloat)self.pageInfoArr.count);
            }
            
            
        }
        
        
        
    }
    // 回调
    
//    return;
    if (self.callback) {
        [self.webView removeFromSuperview];
        self.webView = nil;
        
        self.callback(self.pptImageArr);
    }
}

-(UIImage *)getImageFromSubFrame:(CGRect)subFrame andImage:(UIImage*)image{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGRect subImageRect= subFrame;// CGRectMake(KcutStartX, KcutStartY, KcutWidth, KcutHeight);
    
    CGImageRef imageRef=image.CGImage;
    CGImageRef subImageRef=CGImageCreateWithImageInRect(imageRef, subImageRect);
    CGSize subImageSize= subFrame.size;//
    context = UIGraphicsGetCurrentContext();
    UIGraphicsBeginImageContext(subImageSize);
    CGContextDrawImage(context, subImageRect, subImageRef);
    UIImage *subImage=[UIImage imageWithCGImage:subImageRef];
    UIGraphicsEndImageContext();
    

    return subImage;
    return nil;
}



// 截取响应视图
- (UIImage* )imageWithView:(UIView *)view frame:(CGRect)frame{
    @autoreleasepool {
        UIGraphicsBeginImageContextWithOptions(frame.size, YES, 0.0);
        CGContextRef context = UIGraphicsGetCurrentContext();
        if (!context) {
            return nil;
        }
        [view.layer renderInContext:context];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

//        CGRect subImageRect=frame;// CGRectMake(KcutStartX, KcutStartY, KcutWidth, KcutHeight);
//
//
//        CGImageRef imageRef=image.CGImage;
//        CGImageRef subImageRef=CGImageCreateWithImageInRect(imageRef, subImageRect);
//        CGSize subImageSize= frame.size;//
//        context = UIGraphicsGetCurrentContext();
//        UIGraphicsBeginImageContext(subImageSize);
//        CGContextDrawImage(context, subImageRect, subImageRef);
//        UIImage *subImage=[UIImage imageWithCGImage:subImageRef];
//        UIGraphicsEndImageContext();





        
        NSData *imageData = UIImageJPEGRepresentation(image,0.6);
        UIImage *resultImage = [UIImage imageWithData:imageData];
        
        
        
        return resultImage;
    }
}
//-(void)cutOutImage:(UIImage *)cutedImage  frame:(CGRect)frame{{
//
//    //设置要保存图片的大小
//
//    CGSize subImageSize=cutLocation.textureRect.size;
//
//    //初始化一个矩形，这个矩形是设置剪贴以后图片得大小
//
//    CGRect subImageRect=CGRectMake(KcutStartX, KcutStartY, KcutWidth, KcutHeight);
//
//    CGImageRef imageRef=cutedImage.CGImage;
//
//    CGImageRef subImageRef=CGImageCreateWithImageInRect(imageRef, subImageRect);
//
//    UIGraphicsBeginImageContext(subImageSize);
//
//    CGContextRef context=UIGraphicsGetCurrentContext();
//
//    CGContextDrawImage(context, subImageRect, subImageRef);
//
//    //得到新得图片
//
//    UIImage *subImage=[UIImage imageWithCGImage:subImageRef];
//
//    UIGraphicsEndImageContext();
//
//
//
//}


- (NSMutableArray *)pageInfoArr{
    if (!_pageInfoArr) {
        _pageInfoArr = [NSMutableArray array];
    }
    return _pageInfoArr;
}

- (NSMutableArray *)pptImageArr {
    if (!_pptImageArr) {
        _pptImageArr = [NSMutableArray array];
    }
    return _pptImageArr;
}

- (void)dealloc{
    NSLog(@"%@",self);
}

@end
